<?php session_start(); $_SESSION['page'] = 'client';?>
<!doctype html public "-//W3C//DTD HTML 4.01//EN">

<?php
    $category = $_GET['category'];
    $searchtext = $_GET['searchtext'];
    $libraryNo = $_COOKIE['libraryNo'];
    require ('db_connection.php');

    $qcount = "SELECT MAX(userID) FROM tblclient";
    $rcount = mysql_query($qcount);
    while($row = mysql_fetch_array($rcount))
    {
      $ctr1 = $row['MAX(userID)'];
    }

    if($category == 'All')
    {

        $query = "SELECT * FROM tblclient WHERE libraryNo = '$libraryNo' OR libraryCardNo LIKE '$searchtext' OR lastName LIKE '$searchtext'";
    }
    else{
        $query = "SELECT * FROM tblclient WHERE $category LIKE '%$searchtext' AND libraryNo='$libraryNo'";
    }
    $result = mysql_query($query);

    mysql_close();
?>

<html>
   <head>
      <title>Client List</title>
      <meta http-equiv="generator" content="PHP Designer 2005" />
      <style type="text/css">
        @import url(style.css);
      </style>
   </head>
   
   <script LANGUAGE=javascript>
    <!--
     function check()
     {
        if(document.search_form.searchtext.value=="" )
        {
          alert('Please fill the search box.');
          return false;
        }
        return true;
     }
     //-->
    </script>

   <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000" class=''>


    <table width='80%' align='center' class='content'>
        <tr><td colspan='2'><img src='images/banner.jpg'></td></tr>
        <tr><td align='right' colspan='2' class='logout'><?php require ('loginout.php');?></td></tr>
        <tr class='menuborder'><td width='90%'><img src='images/clientlist.png'></td><td><?php  require('buttons.php'); ?></td></tr>
        <tr><td colspan='2' class='bodyborder'>
            <form method='get' action='clientlist.php' name='search_form' onSubmit="return check();">
            <table align='center'>
            <tr><td height='30'></td></tr>
                <tr><td>Search By</td>
                    <td><select name='category'>
                        <option value='All'>All</option>
                        <option value='lastName'>Last Name</option>
                        <option value='libraryCardNo'>Library Card No.</option>
                        </select>
                    </td>
                    <td><input type='text' name='searchtext' size='40'></td>
                    <td><input type='submit'value='Search' class='tool'></td>
            </tr>
            <tr><td height='30'></td></tr>
            </table>
            </form>
            </td>
        </tr>
        <tr><td colspan='2' class='bodyborder'>
            <table align='center' width='70%'>
                <tr><td height='15'></td></tr>
                <tr align='center'><th colspan='4'>Search Result</th></tr>
                <tr><td height='15'></td></tr>
                <tr><td></td>
                    <td>
                    <?php
                          require('db_connection.php');
                          //$query = "SELECT * FROM tblclient";
                          $result = mysql_query($query);
                          echo "<table class='listborder' cellspacing='0' cellpadding='3'><tr class='listtable'><th>Library Card No</th><th>Name</th></tr>";
                          while ($row = mysql_fetch_array($result))
                            {
                                        $libraryCardNo = $row['libraryCardNo'];
                                        $lastName = $row['lastName'];
                                        $firstName = $row['firstName'];
                                        $userID = $row['userID'];
                                        echo "<tr><td width='20%' class='listborder'><a href=clientedit.php?userID=$userID>$libraryCardNo</a></td>";
                                        echo "<td width='30%' class='listborder'>$lastName, $firstName</td></tr>";
                            }
                          echo "</table>";
                    ?>
                    </td>
                </tr>
                <tr><td height='30'></td></tr>
            </table>
            </td>
        </tr>
        <tr><td align='center' colspan='2'><?php require ('copyright.php')?></td></tr>
    </table>
    </form>

   </body>
</html>
